﻿using CPPEI.WebApi;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using SER = CPPEI.ETL.Domain.Services;
using ENT = CPPEI.ETL.Domain.Entities;
using MOD = CPPEI.ETL.Domain.Models;
using CPPEI.ETL.Domain;

namespace CPPEI.ETL.WebApi
{
    [CPPEI.WebApi.AuthGetAction("ETL", "GetDataServiceTypeList", "1.0")]
    public class GetDataServiceTypeListAction : BaseAction<GetDataServiceTypeListParams, GetDataServiceTypeListResult>
    {
        protected override ActionResult<GetDataServiceTypeListResult> OnExecute(ActionContext context, 
            SysParameters sysParameters,
            GetDataServiceTypeListParams opParams)
        {
            GetDataServiceTypeListResult result = new GetDataServiceTypeListResult();

            List<MOD.MDtSerCategory> list = new SER.CacheService().GetDtSerCategoryList();
            foreach (var mCategory in list)
            {
                GetDataServiceTypeListResult.Category category = new GetDataServiceTypeListResult.Category();
                category.Id = mCategory.Id;
                //category.Icon = string.Format("{0}{1}", Configs.WebBaseAddress, mCategory.Icon);
                category.Caption = mCategory.Caption;
                category.Description = mCategory.Description;

                foreach (var mType in mCategory.TypeList)
                {
                    GetDataServiceTypeListResult.Item item = new GetDataServiceTypeListResult.Item();
                    item.Id = mType.Id;
                    item.Caption = mType.Caption;
                    item.Description = mType.Description;
                    //item.Icon = string.Format("{0}{1}", Configs.WebBaseAddress, mType.Icon);

                    category.Items.Add(item);
                }

                result.Categories.Add(category);
            }

            return new ActionResult<GetDataServiceTypeListResult>(result);
        }
    }
    public class GetDataServiceTypeListParams
    {
    }

    public class GetDataServiceTypeListResult
    {
        public List<Category> Categories { get; set; }

        public GetDataServiceTypeListResult()
        {
            Categories = new List<Category>();
        }

        public class Category
        {
            public Guid Id { get; set; }
            public string Caption { get; set; }
            public string Description { get; set; }
            //public string Icon { get; set; }

            public List<Item> Items { get; set; }
            public Category()
            {
                Items = new List<Item>();
            }
        }
        
        public class Item
        {
            public Guid Id { get; set; }
            public string Caption { get; set; }
            public string Description { get; set; }
            //public string Icon { get; set; }
        }
    }
}
